package com.guan.ordering_sys.generator.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guan.ordering_sys.common.StateCode;
import com.guan.ordering_sys.exception.BaseException;
import com.guan.ordering_sys.generator.entity.EmployeePost;
import com.guan.ordering_sys.generator.mapper.EmployeePostMapper;
import com.guan.ordering_sys.generator.service.EmployeePostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  EmployeePostServiceImpl服务实现类
 * </p>
 *
 * @author 关远键
 * @since 2021-06-18
 */
@Service
public class EmployeePostServiceImpl extends ServiceImpl<EmployeePostMapper, EmployeePost> implements EmployeePostService {

    @Autowired
    private EmployeePostMapper epMapper;

    /**
     * 给雇员添加角色权限
     * @author 关远键
     * @date 2021/6/27 22:54
     * @param ep
     * @return boolean
     */
    @Override
    public boolean insert(EmployeePost ep) {
        if (epMapper.isExits(ep) > 0) {
            throw new BaseException(StateCode.FAIL);
        }

        if (epMapper.insert(ep) > 0) {
            return true;
        } else {
            throw new BaseException(StateCode.DAO_EXCEPTION);
        }
    }

    /**
     * 根据角色编号获取所有雇员编号
     * @author 关远键
     * @date 2021/6/27 23:01
     * @param id
     * @return java.util.List<java.lang.Integer>
     */
    @Override
    public List<Integer> getListByPostId(Integer id) {
        List<Integer> list = epMapper.getListByPostId(id);
        if (list.size() == 0) {
            throw new BaseException(StateCode.NOT_FOUND);
        }
        return list;
    }

    /**
     * 根据雇员编号获取角色编号
     * @author 关远键
     * @date 2021/6/27 23:23
     * @param id
     * @return java.util.List<java.lang.Integer>
     */
    @Override
    public List<Integer> getPostIdByEmployeeId(Long id) {
        List<Integer> list = epMapper.getPostIdByEmployeeId(id);
        if (list.size() == 0) {
            throw new BaseException(StateCode.NOT_FOUND);
        }
        return list;
    }

}
